package com.kg.sdk.adapt;

import android.os.Parcel;
import android.os.Parcelable;

import com.kg.sdk.util.KPNetworkData;

import org.json.JSONException;
import org.json.JSONObject;

public class KPGiftData implements Parcelable {
    public int id = 1;
    public int gid = 20;
    public int sort = 0;
    public int total = 2652;
    public int used = 5;
    public String name = "暑期礼包";
    public String desc = "暑期礼包【200钻石】";
    public String usedcode = "";
    public String tag = "";
    public String tagName = "";
    public KPGiftData(String data){
        try {
            JSONObject jsonObject = new JSONObject(data);
            init(jsonObject);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    public KPGiftData(JSONObject jsonObject){
        init(jsonObject);
    }

    private void init(JSONObject jsonObject){
        try {
            id = jsonObject.getInt(KPNetworkData.ID_KEY);
            gid = jsonObject.getInt(KPNetworkData.GID_KEY);
            sort = jsonObject.getInt(KPNetworkData.SORT_KEY);
            total = jsonObject.getInt(KPNetworkData.TOTAL_KEY);
            used = jsonObject.getInt(KPNetworkData.USED_KEY);
            name = jsonObject.getString(KPNetworkData.NAME_KEY);
            desc = jsonObject.getString(KPNetworkData.DESE_KEY);
            usedcode = jsonObject.getString(KPNetworkData.USEDCODE_KEY);
            tag = jsonObject.getString(KPNetworkData.TAG_KEY);
            JSONObject tagJson = new JSONObject(tag);
            tagName = tagJson.getString(KPNetworkData.TAG_KEY);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    protected KPGiftData(Parcel in) {
        id = in.readInt();
        gid = in.readInt();
        sort = in.readInt();
        total = in.readInt();
        used = in.readInt();
        name = in.readString();
        desc = in.readString();
        usedcode = in.readString();
        tag = in.readString();
    }

    public static final Creator<KPGiftData> CREATOR = new Creator<KPGiftData>() {
        @Override
        public KPGiftData createFromParcel(Parcel in) {
            return new KPGiftData(in);
        }

        @Override
        public KPGiftData[] newArray(int size) {
            return new KPGiftData[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeInt(gid);
        dest.writeInt(sort);
        dest.writeInt(total);
        dest.writeInt(used);
        dest.writeString(name);
        dest.writeString(desc);
        dest.writeString(usedcode);
        dest.writeString(tag);
    }
    // {"id":1,"gid":20,"name":"暑期礼包","desc":"暑期礼包【200钻石】",
    // "sort":0,"total":2652,"used":5,"usedcode":"5wiuyesfe","tag":{"id":7,"tag":"统一码","class":"r3"}}


}
